home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 98 / Skunkware 98.iso / src / mail / pine3.96.tar.gz / pine3.96.tar / pine3.96 / pine / osdep / execview.dos < prev    next >
Text File  |  1996-04-25  |  4KB  |  173 lines

  1. #line 2 "osdep/execview.dos"
  2. /*----------------------------------------------------------------------
  3.     Routine to execute command mailcap says is used to display MIME segment
  4.     under MS-DOS
  5.  
  6.  The exported routine is:
  7.  
  8.     exec_viewer -- 
  9.  
  10.  ----*/
  11.  
  12. #include    <process.h>
  13.  
  14.  
  15. /* ----------------------------------------------------------------------
  16.    Execute the given 
  17.  
  18.   Args: cmd -- 
  19.     image_file --
  20.   
  21.      
  22.   ----*/
  23. void
  24. exec_mailcap_cmd(cmd, image_file, needsterminal)
  25.     char *cmd;
  26.     char *image_file;
  27.     int   needsterminal;  /* not used in DOS */
  28. {
  29. #ifdef    OLDWAY
  30. #define    MAXARGS    10
  31.     char     *args[MAXARGS], command[MAXPATH], *cp = command;
  32.     int       i;
  33.  
  34.     /* build args */
  35. /* MAJOR HACK JUST FOR NOW */
  36.     if(struncmp(type_desc(body->type, body->subtype, body->parameter, 1),
  37.         "audio", 5) == 0){
  38.     if(getenv("PINEHOME"))
  39.       sprintf(command,"%s\\sound", getenv("PINEHOME"));
  40.     else
  41.       strcpy(command, "c:\\pine\\sound");
  42.     args[0] = command;
  43.     args[1] = image_file;
  44.     args[2] = "27";
  45.     args[3] = NULL;
  46.     }
  47.     else {
  48.     strncpy(command, ps_global->VAR_IMAGE_VIEWER, MAXPATH);
  49.     for(i=0; *cp != '\0';i++){            /* build args array */
  50.         if(i < MAXARGS+2){
  51.         args[i] = NULL;            /* in case we break out */
  52.         }
  53.         else{
  54.         q_status_message1(SM_ORDER | SM_DING, 3, 5,
  55.                   "Too many args : %s",
  56.                   ps_global->VAR_IMAGE_VIEWER);
  57.         return;
  58.         }
  59.  
  60.         while(isspace((unsigned char)(*cp)))
  61.           if(*cp != '\0')
  62.         cp++;
  63.           else
  64.         break;
  65.  
  66.         args[i] = cp;
  67.  
  68.         while(!isspace((unsigned char)(*cp)))
  69.           if(*cp != '\0')
  70.         cp++;
  71.           else
  72.         break;
  73.  
  74.         if(*cp != '\0')
  75.           *cp++ = '\0';
  76.     }
  77.     args[i++] = image_file;
  78.     args[i] = NULL;
  79.     }
  80.  
  81.     /* actually display the sucker */
  82.     if(spawnv(_P_WAIT, args[0], args) == -1){
  83.     /* error spawning image viewer */
  84.         q_status_message2(SM_ORDER | SM_DING, 4, 5,
  85.                           "Error \"%s\" spawning %s",
  86.                           error_description(errno),
  87.               ps_global->VAR_IMAGE_VIEWER); 
  88.     return;
  89.     }
  90.  
  91.     /* let main loop know we messed with the display */
  92.     ps_global->mangled_screen = 1;
  93.     q_status_message1(SM_ORDER, 0, 4, "Display of %s complete",
  94.               type_desc(body->type, body->subtype, 
  95.                 body->parameter, 1));
  96. #endif    /* OLDWAY */
  97.     int   rc;
  98.  
  99.     cancel_busy_alarm(1);
  100.  
  101.     if(system(cmd) < 0)
  102.       q_status_message1(SM_ORDER, 3, 4, "Failed to exec viewer: %s",
  103.             (errno == E2BIG) ? "Argument list too big" :
  104.               (errno == ENOENT) ? "No command interpreter" :
  105.                 (errno == ENOMEM) ? "Not enough memory"
  106.                 : "Unknown Error");
  107.  
  108.     unlink(image_file);
  109. }
  110.  
  111.  
  112. /* ----------------------------------------------------------------------
  113.    Execute the given test= cmd
  114.  
  115.   Args: cmd -- command to execute
  116.   Returns exit status
  117.      
  118.   ----*/
  119. int
  120. exec_mailcap_test_cmd(cmd)
  121.     char *cmd;
  122. {
  123. #define    MAXARGS    10
  124.     char *args[MAXARGS], *cp;
  125.     int   i, rv;
  126.  
  127.     cp = cmd;
  128.  
  129.     /* build args */
  130.     for(i=0; *cp != '\0'; i++){            /* build args array */
  131.     if(i < MAXARGS+2){
  132.         args[i] = NULL;            /* in case we break out */
  133.     }
  134.     else{
  135.         q_status_message1(SM_ORDER | SM_DING, 3, 5,
  136.                   "Too many args : %s",
  137.                   ps_global->VAR_IMAGE_VIEWER);
  138.         return -1;
  139.     }
  140.  
  141.     while(isspace((unsigned char)(*cp)))
  142.       if(*cp != '\0')
  143.         cp++;
  144.       else
  145.         break;
  146.  
  147.     args[i] = cp;
  148.  
  149.     while(!isspace((unsigned char)(*cp)))
  150.       if(*cp != '\0')
  151.         cp++;
  152.       else
  153.         break;
  154.  
  155.     if(*cp != '\0')
  156.       *cp++ = '\0';
  157.     }
  158.     args[i] = NULL;
  159.  
  160.     /* actually display the sucker */
  161.     if((rv = spawnvp(_P_WAIT, args[0], args)) == -1){
  162.     /* error spawning image viewer */
  163.         q_status_message2(SM_ORDER | SM_DING, 4, 5, "Error \"%s\" spawning %s",
  164.                           error_description(errno),
  165.               ps_global->VAR_IMAGE_VIEWER); 
  166.     return -1;
  167.     }
  168.  
  169.     return(rv);
  170. }
  171.  
  172.  
  173.